<?php

namespace app\admin\model;

/**
 * 打标作业
 */
class Operation extends BaseModel
{
    protected $autoWriteTimestamp = 'int';

    protected $createTime         = 'create_time';

    protected $updateTime         = 'update_time';

    protected $name               = 'operation';

    public function unit()
    {
        return $this->hasOne(Unit::class, 'id', 'organization_id');
    }

    public function abnormal()
    {
        return $this->hasOne(Abnormal::class, 'id', 'exception_category');
    }

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'create_user');
    }
    public function verify()
    {
        return $this->hasOne(User::class, 'id', 'verify_user');
    }

    public function street()
    {
        return $this->hasOne(Street::class, 'id', 'street_id');
    }

    public function readUser()
    {
        return $this->belongsToMany(User::class, 'operation_read');
    }

    public function getOperationCategoryNameAttr($val, $data)
    {
        $map = [
            1 => '疑似隐患',
            2 => '无隐患',
            3 => '已处罚',
        ];
        return isset($map[$data['operation_category']]) ? $map[$data['operation_category']] : '';
    }
}